﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using System.Data;

namespace DataService
{
    // NOTE: If you change the class name "Service1" here, you must also update the reference to "Service1" in App.config.
    public class Service1 : IService1
    {
        public string GetData(int value)
        {
            return string.Format("You entered: {0}", value);
        }

        public CompositeType GetDataUsingDataContract(CompositeType composite)
        {
            if (composite.BoolValue)
            {
                composite.StringValue += "Suffix";
            }
            return composite;
        }
        //-------------------------------ARTISTS----------------------------------------//
        
        /// <summary>
        /// Get all artists
        /// </summary>
        /// <returns>
        /// Returns artists DataTable
        /// </returns>
        public DataEntityTier.OpenRecordsDataSet.ArtistsDataTable GetArtists()
        {
            DataAccessTier.OpenRecordsDataSetTableAdapters.ArtistsTableAdapter 
                ArtistsTableAdapter1 = new
                DataAccessTier.OpenRecordsDataSetTableAdapters.ArtistsTableAdapter();
            return ArtistsTableAdapter1.GetArtists();
        }

        /// <summary>
        /// Updates changes to ArtistDataTable
        /// </summary>
        /// <param name="ArtistDataTable"></param>
        public void UpdateArtists(DataEntityTier.OpenRecordsDataSet.ArtistsDataTable ArtistDataTable)
        {
            DataAccessTier.OpenRecordsDataSetTableAdapters.ArtistsTableAdapter
                ArtistsTableAdapter1 = new
                DataAccessTier.OpenRecordsDataSetTableAdapters.ArtistsTableAdapter();
            ArtistsTableAdapter1.Update(ArtistDataTable);
        }

        public int GetArtistID(string artistName)
        {
            DataAccessTier.OpenRecordsDataSetTableAdapters.ArtistsTableAdapter
                ArtistsTableAdapter1 = new
                DataAccessTier.OpenRecordsDataSetTableAdapters.ArtistsTableAdapter();

            return Convert.ToInt32(ArtistsTableAdapter1.GetArtistID(artistName));
        }

        //-------------------------------PROJECTS----------------------------------------//

        /// <summary>
        /// Get all projects
        /// </summary>
        /// <returns>
        /// Returns projects DataTable
        /// </returns>
        public DataEntityTier.OpenRecordsDataSet.ProjectsDataTable GetProjects()
        {
            DataAccessTier.OpenRecordsDataSetTableAdapters.ProjectsTableAdapter
                ProjectsTableAdapter1 = new
                DataAccessTier.OpenRecordsDataSetTableAdapters.ProjectsTableAdapter();

            return ProjectsTableAdapter1.GetProjects();
        }

        //same method as above - find where it is used and delete it
        public DataEntityTier.OpenRecordsDataSet.ProjectsDataTable GetAllProjectName()
        {
            DataAccessTier.OpenRecordsDataSetTableAdapters.ProjectsTableAdapter
                ProjectsTableAdapter1 = new
                DataAccessTier.OpenRecordsDataSetTableAdapters.ProjectsTableAdapter();

            return ProjectsTableAdapter1.GetProjects();
        }

        //Update Projects
        public void UpdateProjects(DataEntityTier.OpenRecordsDataSet.ProjectsDataTable ProjectsDataTable)
        {
            DataAccessTier.OpenRecordsDataSetTableAdapters.ProjectsTableAdapter
                ProjectsTableAdapter1 = new
                DataAccessTier.OpenRecordsDataSetTableAdapters.ProjectsTableAdapter();

            ProjectsTableAdapter1.Update(ProjectsDataTable);
        }

        public DataEntityTier.OpenRecordsDataSet.ProjectsDataTable GetProjectByArtistID(int artistID)
        {
            DataAccessTier.OpenRecordsDataSetTableAdapters.ProjectsTableAdapter
                ProjectsTableAdapter1 = new
                DataAccessTier.OpenRecordsDataSetTableAdapters.ProjectsTableAdapter();

            return ProjectsTableAdapter1.GetProjectByArtistID(artistID);
        }



        /// <summary>
        /// Select a project by the project name
        /// </summary>
        /// <param name="projectName"></param>
        /// <returns>
        /// Projects DataTable
        /// </returns>
        public DataEntityTier.OpenRecordsDataSet.ProjectsDataTable 
            GetProjectsByProjectName(string projectName)
        {
            DataAccessTier.OpenRecordsDataSetTableAdapters.ProjectsTableAdapter
               ProjectsTableAdapter1 = new
               DataAccessTier.OpenRecordsDataSetTableAdapters.ProjectsTableAdapter();

            return null; // ProjectsTableAdapter1.GetProjectsByProjectName(projectName);
        }

        /// <summary>
        /// Inserts a new project name into projects table
        /// </summary>
        /// <param name="projectName"></param>
        public void InsertProjectName(string projectName)
        {
            DataAccessTier.OpenRecordsDataSetTableAdapters.ProjectsTableAdapter
               ProjectsTableAdapter1 = new
               DataAccessTier.OpenRecordsDataSetTableAdapters.ProjectsTableAdapter();

            ProjectsTableAdapter1.InsertProjectName(projectName);
        }

        /// <summary>
        /// Get the project id by project name
        /// </summary>
        /// <param name="projectName"></param>
        /// <returns></returns>
        public DataEntityTier.OpenRecordsDataSet.ProjectsDataTable GetProjectIDByProjectName(string projectName)
        {
            DataAccessTier.OpenRecordsDataSetTableAdapters.ProjectsTableAdapter
                ProjectsTableAdapter1 = new
                DataAccessTier.OpenRecordsDataSetTableAdapters.ProjectsTableAdapter();

            return ProjectsTableAdapter1.GetProjectIdByProjectName(projectName);
        }

        //-------------------------------MANAGERS----------------------------------------//

        //Get Managers
        public DataEntityTier.OpenRecordsDataSet.ManagersDataTable GetManagers()
        {
            DataAccessTier.OpenRecordsDataSetTableAdapters.ManagersTableAdapter
                ManagersTableAdapter1 = new
                DataAccessTier.OpenRecordsDataSetTableAdapters.ManagersTableAdapter();

            return ManagersTableAdapter1.GetManagers();
        }      

        //-------------------------------TRACKS----------------------------------------//

        public void DeleteAllTracks()
        {
            DataAccessTier.OpenRecordsDataSetTableAdapters.TracksTableAdapter
                TracksTableAdapter1 = new
                DataAccessTier.OpenRecordsDataSetTableAdapters.TracksTableAdapter();

            DataAccessTier.OpenRecordsDataSetTableAdapters.TrackSalesTableAdapter
               TrackSalesTableAdapter1 = new
               DataAccessTier.OpenRecordsDataSetTableAdapters.TrackSalesTableAdapter();

            TrackSalesTableAdapter1.DeleteQuery();

            TracksTableAdapter1.DeleteQuery();
        }

        public DataEntityTier.OpenRecordsDataSet.TracksDataTable GetTrackIDbyTrackName(string trackName)
        {
            DataAccessTier.OpenRecordsDataSetTableAdapters.TracksTableAdapter
                TracksTableAdapter1 = new
                DataAccessTier.OpenRecordsDataSetTableAdapters.TracksTableAdapter();

            return TracksTableAdapter1.GetTrackIDbyTrackName(trackName);
        }

        //insert track with projectID, track name and track version
        public void InsertTrackData(int projectID, string trackVersion, string trackName)
        {
            DataAccessTier.OpenRecordsDataSetTableAdapters.TracksTableAdapter
                TracksTableAdapter1 = new
                DataAccessTier.OpenRecordsDataSetTableAdapters.TracksTableAdapter();

            TracksTableAdapter1.InsertTrackData(projectID, trackVersion, trackName);
        }

        //insert track salse data with projectID, track name and track version
        public void InsertTrackSales(int trackID, string date, int salesQuarter, int trackSales)
        {
            DataAccessTier.OpenRecordsDataSetTableAdapters.TrackSalesTableAdapter
                TrackSalesTableAdapter1 = new
                DataAccessTier.OpenRecordsDataSetTableAdapters.TrackSalesTableAdapter();

            TrackSalesTableAdapter1.InsertTrackSales(trackID, date, salesQuarter, trackSales);
        }
         
        //Get Tracks
        public DataEntityTier.OpenRecordsDataSet.TracksDataTable GetTracks()
        {
            DataAccessTier.OpenRecordsDataSetTableAdapters.TracksTableAdapter
                TracksTableAdapter1 = new
                DataAccessTier.OpenRecordsDataSetTableAdapters.TracksTableAdapter();

            return TracksTableAdapter1.GetTracks();
        }

        //Get Tracks by project ID
        public DataEntityTier.OpenRecordsDataSet.TracksDataTable 
            GetTracksByProjectID(int projectID)
        {
            DataAccessTier.OpenRecordsDataSetTableAdapters.TracksTableAdapter
                TracksTableAdapter1 = new
                DataAccessTier.OpenRecordsDataSetTableAdapters.TracksTableAdapter();

            return TracksTableAdapter1.GetTracksByProjectID(projectID);
        }

        //Get Tracks by project ID and TrackName
        public DataEntityTier.OpenRecordsDataSet.TracksDataTable 
            GetTracksByProjectIDTrackName(int projectID, string trackName)
        {
            DataAccessTier.OpenRecordsDataSetTableAdapters.TracksTableAdapter
                TracksTableAdapter1 = new
                DataAccessTier.OpenRecordsDataSetTableAdapters.TracksTableAdapter();

            return TracksTableAdapter1.GetTracksByProjectIDTrackName(projectID, trackName);         
        }

        //get track id by projectID trackName and trackVersion
        public DataEntityTier.OpenRecordsDataSet.TracksDataTable
          GetTrackID(int projectID, string trackVersion, string trackName)
        {
            DataAccessTier.OpenRecordsDataSetTableAdapters.TracksTableAdapter
                TracksTableAdapter1 = new
                DataAccessTier.OpenRecordsDataSetTableAdapters.TracksTableAdapter();

            return TracksTableAdapter1.GetTrackID(projectID, trackVersion, trackName);
        }

        //------------------------------TRACK SALES-------------------------------------------//

        //gets tracks sales
        public DataEntityTier.OpenRecordsDataSet.TrackSalesDataTable GetTrackSales()
        {
            DataAccessTier.OpenRecordsDataSetTableAdapters.TrackSalesTableAdapter
                TrackSalesTableAdapter1 = new
                DataAccessTier.OpenRecordsDataSetTableAdapters.TrackSalesTableAdapter();

            return TrackSalesTableAdapter1.GetTrackSales();
        }

        public int GetTotalTrackSales(int trackID)
        {
            DataAccessTier.OpenRecordsDataSetTableAdapters.TrackSalesTableAdapter
              TrackSalesTableAdapter1 = new
              DataAccessTier.OpenRecordsDataSetTableAdapters.TrackSalesTableAdapter();

            return Convert.ToInt32(TrackSalesTableAdapter1.GetTotalTrackSales(trackID));
        }

        public int GetTrackSalesByYear(decimal year, int trackID)
        {
            DataAccessTier.OpenRecordsDataSetTableAdapters.TrackSalesTableAdapter
                TrackSalesTableAdapter1 = new
                DataAccessTier.OpenRecordsDataSetTableAdapters.TrackSalesTableAdapter();

            return Convert.ToInt32(TrackSalesTableAdapter1.GetTrackSalesByYear(year, trackID));
        }

        public int GetTrackSalesByQuarter(decimal year, int trackID, int salesQuarter)
        {
            DataAccessTier.OpenRecordsDataSetTableAdapters.TrackSalesTableAdapter
                TrackSalesTableAdapter1 = new
                DataAccessTier.OpenRecordsDataSetTableAdapters.TrackSalesTableAdapter();

            return Convert.ToInt32(TrackSalesTableAdapter1.GetTrackSalesByQuarter(year, trackID, salesQuarter));
        }

        //-------------------------------EXCELL INVOICE----------------------------------------//
      
        public DataTable GetInvoiceData(String filePath)
        {
            //return new DataAccessTier.ExcelInvoice().GetInvoiceData(FilePath);

            return new DataAccessTier.ExcelInvoice().GetSalesData(filePath);
        }

        public int GetSalesQuarter(String filePath)
        {
            return new DataAccessTier.ExcelInvoice().GetSalesQuarter(filePath);
        }
    }
}
